package com.inlycat.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jarvan4dev@163.com
 * @since 2015年8月20日下午4:49:15
 * @category 复合查询条件
 **/
public class Criteria<T> {

	private List<Condition> conditions = new ArrayList<Condition>();


	public Criteria<T> add(Condition condition) {
		conditions.add(condition);
		return this;
	}

	public String getCondition() {

		StringBuilder queryBuilder = new StringBuilder();
		if (!conditions.isEmpty()) {
			for (Condition condition : conditions) {
				queryBuilder.append(condition.getPropertyName() + " "
						+ condition.getOperator() + " ? AND ");
			}
		}
		String query = queryBuilder.toString();
		query = query.substring(0, query.lastIndexOf("AND"));
		return query;
	}
}
